#region Librerias

using System;
using ESF.GTK;
using ESF.SFT.FileUploader.SharedResources;
using Gtk;
using System.ComponentModel;
using ESF.GTK.Elements;
using ESF.SFT.FileUploader.Presenter.FileSelection;
using ESF.General;
using ESF.General.Entity;
using System.Collections.ObjectModel;
using ESF.General.Text;
using System.IO;
using System.Collections.Generic;

#endregion


namespace ESF.SFT.FileUploaderGTK
{
	public partial class FileUploaderWindow : BaseGTKWindow<FileUploaderWindowPresenter, IFileUploaderWindowViewer>, IFileUploaderWindowViewer
	{
		#region Miembros

		private BackgroundWorker _BgUpload;
		private BackgroundWorker _BgValidate;


		private Gtk.FileChooserDialog _FileDialog; 

		private PaggingInfo _PaggingInfo;

		private ObservableCollection<FileData> _SelectedFiles;

		private List<FileSystemWatcher> _FSWatchers;

		private Dictionary<string, DateTime> _FSWRefreshTimes;

		#endregion
		
		
		#region Constructor

		public FileUploaderWindow()
			: base()
		{
			Build ();

			imgInfo.Pixbuf = GTKConverter.ImageToPixbuf (SharedImages.Info_32x32);

			imgSelectedFiles.Pixbuf = GTKConverter.ImageToPixbuf(SharedImages.Computer_64x64);

			imgSentFiles.Pixbuf = GTKConverter.ImageToPixbuf(SharedImages.HardDiskServer_64x64);


			_Presenter = new FileUploaderWindowPresenter(this);
			_Presenter.Load();


			_FileDialog = new Gtk.FileChooserDialog ("Seleccione archivo(s)", this, FileChooserAction.Open);
			_FileDialog.SelectMultiple = true;

			// TODO: Instanciar un _ValidationLogViewer

			// TODO: Instanciar un _ConfigureDigitalFileSign

			_PaggingInfo = new PaggingInfo();
			_PaggingInfo.PageSize = 10;


			_SelectedFiles = new ObservableCollection<FileData>();

			// TODO: es vinculable el modelo del treeview coomo lo es el del wpf gridview?

			_FSWatchers = new List<FileSystemWatcher>();

			_FSWRefreshTimes = new Dictionary<string, DateTime>();
		}

		#endregion


		#region Window Events
		
		protected void OnDeleteEvent (object o, DeleteEventArgs args)
		{
			CloseApplication ();
		}
		
		#endregion


		#region Background Worker Events

		protected void _Bg_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
		{
			if (e.Error != null)
			{
				LogError(e.Error);

				return;
			}

			Log.StopOps();

			Application.Invoke(delegate { Hide(); });
		}

		#endregion


		#region Interface Fields

		public string ProductVersion
		{
			set { stsStatusBar.TooltipText = value; }
		}

		#endregion
	}
}

